/******************************************************************************
 *                  Shanghai ChipON Micro-Electronic Co.,Ltd
 ******************************************************************************
 *  @File Name        : kf8a100fxx_gpio.c
 *  @Author           : ChipON AE/FAE Group
 *  @Date             : 2023-12-19
 *  @HW Version       : KF8A100Fxx
 *  @Lib Version      : V2.0.1
 *  @Description      : This file provides the driver for the gpio module
 ******************************************************************************
 *  Copyright (C) by Shanghai ChipON Micro-Electronic Co.,Ltd
 *  All rights reserved.
 *
 *  This software is copyright protected and proprietary to
 *  Shanghai ChipON Micro-Electronic Co.,Ltd.
 *****************************************************************************/
/******************************************************************************
 *  |Date        |Version  |Author       |Description
 ******************************************************************************
 *  |2023-12-25  |V2.0     |Zhong Yusheng|New creat
 *****************************************************************************/

/******************************************************************************
 **                     QAC Warnings
 *****************************************************************************/
/* PRQA S 0436 EOF #8-bit MCU Features: Direct Write Registers. */
/* PRQA S 1291, 1820, 1821, 1822, 1823, 1851, 1853, 3715, 3757, 3760 EOF #Registers are essentially unsigned numbers. */
/* PRQA S 2754 EOF #Level 7 problem due to unsupported assembly instructions. */
/* PRQA S 3768, 3771, 4130, 4393, 4434, 4443, 4446, 4461, 4532 EOF #Registers are essentially unsigned numbers. */

/******************************************************************************
 *                      Include Files
 *****************************************************************************/
#include "kf8a100fxx_gpio.h"
/******************************************************************************
 *                      Macro Definitions
 *****************************************************************************/

/******************************************************************************
 *                      Constants
 *****************************************************************************/

/******************************************************************************
 *                      Type definitions
 *****************************************************************************/

/******************************************************************************
 *                      Variables
 *****************************************************************************/

/******************************************************************************
 *                      Function definitions
 *****************************************************************************/
/**
 * @brief P0 Port Direction Control
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = The corresponding pin is configured as output
 * 1 = The corresponding pin is configured as input
 */
void Gpio_P0_DirCfg(Gpio_PinMaskType GpioPin, Gpio_PinDirType State)
{
    if (State == GPIO_INPUT)
    {
        TR0 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        TR0 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P0 Digital Port Configuration
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = Configure the corresponding pin as a digital port or special function pin
 * 1 = Configure the corresponding pin as an analog port
 */
void Gpio_P0_AnsCfg(Gpio_PinMaskType GpioPin, Gpio_PinAnsType State)
{
    if (State == GPIO_ANALOG)
    {
        ANS0 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        ANS0 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P0 Port Output Latch Settings
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = Configure the corresponding pin as low level
 * 1 = Configure the corresponding pin as high level
 */
void Gpio_P0_OutLat(Gpio_PinMaskType GpioPin, Gpio_PinLevType State)
{
    if (State == GPIO_HIGH_LEVEL)
    {
        P0LR |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        P0LR &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P0 Pull-up Function Enable
 * The pull-up resistor function can only be enabled when the pin is set as a digital input.
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 1 = Enable the corresponding port pull-up function
 * 0 = Prohibit the corresponding port pull-up function
 */
void Gpio_P0_PurEn(Gpio_PinMaskType GpioPin, Gpio_PinPurType State)
{
    if (State == GPIO_PUR_EN)
    {
        PUR0 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        PUR0 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P0 Port Level Fluctuation Interrupt Enable
 * 1. The level change interrupt function can be enabled only when a pin is set as a digital input, and the level change
 * interrupt function will be disabled automatically when a pin is set as an output or analog input. If a pin is set as
 * output or analog input, the level change interrupt function of the pin will be disabled automatically.
 * 2. The level change interrupt of each pin of P0 port shares one interrupt enable bit and one interrupt response flag
 * bit.
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 1 = Enable the level fluctuation interrupt of the corresponding pin
 * 0 = Disable the level fluctuation interrupt of the corresponding pin
 */
void Gpio_P0_IocEn(Gpio_PinMaskType GpioPin, Gpio_PinIocType State)
{
    if (State == GPIO_IOC_EN)
    {
        IOCL0 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        IOCL0 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P1 Port Direction Control
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = The corresponding pin is configured as output
 * 1 = The corresponding pin is configured as input
 */
void Gpio_P1_DirCfg(Gpio_PinMaskType GpioPin, Gpio_PinDirType State)
{
    if (State == GPIO_INPUT)
    {
        TR1 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        TR1 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P1 Digital Port Configuration
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = Configure the corresponding pin as a digital port or special function pin
 * 1 = Configure the corresponding pin as an analog port
 */
void Gpio_P1_AnsCfg(Gpio_PinMaskType GpioPin, Gpio_PinAnsType State)
{
    if (State == GPIO_ANALOG)
    {
        ANS1 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        ANS1 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P1 Port Output Latch Settings
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = Configure the corresponding pin as low level
 * 1 = Configure the corresponding pin as high level
 */
void Gpio_P1_OutLat(Gpio_PinMaskType GpioPin, Gpio_PinLevType State)
{
    if (State == GPIO_HIGH_LEVEL)
    {
        P1LR |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        P1LR &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P1 Pull-up Function Enable
 * The pull-up resistor function can only be enabled when the pin is set as a digital input.
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 1 = Enable the corresponding port pull-up function
 * 0 = Prohibit the corresponding port pull-up function
 */
void Gpio_P1_PurEn(Gpio_PinMaskType GpioPin, Gpio_PinPurType State)
{
    if (State == GPIO_PUR_EN)
    {
        PUR1 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        PUR1 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P2 Port Direction Control
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = The corresponding pin is configured as output
 * 1 = The corresponding pin is configured as input
 */
void Gpio_P2_DirCfg(Gpio_PinMaskType GpioPin, Gpio_PinDirType State)
{
    if (State == GPIO_INPUT)
    {
        TR2 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        TR2 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P2 Digital Port Configuration
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = Configure the corresponding pin as a digital port or special function pin
 * 1 = Configure the corresponding pin as an analog port
 */
void Gpio_P2_AnsCfg(Gpio_PinMaskType GpioPin, Gpio_PinAnsType State)
{
    if (State == GPIO_ANALOG)
    {
        ANS2 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        ANS2 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P2 Port Output Latch Settings
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = Configure the corresponding pin as low level
 * 1 = Configure the corresponding pin as high level
 */
void Gpio_P2_OutLat(Gpio_PinMaskType GpioPin, Gpio_PinLevType State)
{
    if (State == GPIO_HIGH_LEVEL)
    {
        P2LR |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        P2LR &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P2 Pull-up Function Enable
 * The pull-up resistor function can only be enabled when the pin is set as a digital input.
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 1 = Enable the corresponding port pull-up function
 * 0 = Prohibit the corresponding port pull-up function
 */
void Gpio_P2_PurEn(Gpio_PinMaskType GpioPin, Gpio_PinPurType State)
{
    if (State == GPIO_PUR_EN)
    {
        PUR2 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        PUR2 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P3 Port Direction Control
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = The corresponding pin is configured as output
 * 1 = The corresponding pin is configured as input
 */
void Gpio_P3_DirCfg(Gpio_PinMaskType GpioPin, Gpio_PinDirType State)
{
    if (State == GPIO_INPUT)
    {
        TR3 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        TR3 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P3 Digital Port Configuration
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = Configure the corresponding pin as a digital port or special function pin
 * 1 = Configure the corresponding pin as an analog port
 */
void Gpio_P3_AnsCfg(Gpio_PinMaskType GpioPin, Gpio_PinAnsType State)
{
    if (State == GPIO_ANALOG)
    {
        ANS3 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        ANS3 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P3 Port Output Latch Settings
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = Configure the corresponding pin as low level
 * 1 = Configure the corresponding pin as high level
 */
void Gpio_P3_OutLat(Gpio_PinMaskType GpioPin, Gpio_PinLevType State)
{
    if (State == GPIO_HIGH_LEVEL)
    {
        P3LR |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        P3LR &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P3 Pull-up Function Enable
 * The pull-up resistor function can only be enabled when the pin is set as a digital input.
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 1 = Enable the corresponding port pull-up function
 * 0 = Prohibit the corresponding port pull-up function
 */
void Gpio_P3_PurEn(Gpio_PinMaskType GpioPin, Gpio_PinPurType State)
{
    if (State == GPIO_PUR_EN)
    {
        PUR3 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        PUR3 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P4 Port Direction Control
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = The corresponding pin is configured as output
 * 1 = The corresponding pin is configured as input
 */
void Gpio_P4_DirCfg(Gpio_PinMaskType GpioPin, Gpio_PinDirType State)
{
    if (State == GPIO_INPUT)
    {
        TR4 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        TR4 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P4 Digital Port Configuration
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = Configure the corresponding pin as a digital port or special function pin
 * 1 = Configure the corresponding pin as an analog port
 */
void Gpio_P4_AnsCfg(Gpio_PinMaskType GpioPin, Gpio_PinAnsType State)
{
    if (State == GPIO_ANALOG)
    {
        ANS4 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        ANS4 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P4 Port Output Latch Settings
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = Configure the corresponding pin as low level
 * 1 = Configure the corresponding pin as high level
 */
void Gpio_P4_OutLat(Gpio_PinMaskType GpioPin, Gpio_PinLevType State)
{
    if (State == GPIO_HIGH_LEVEL)
    {
        P4LR |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        P4LR &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P4 Pull-up Function Enable
 * The pull-up resistor function can only be enabled when the pin is set as a digital input.
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 1 = Enable the corresponding port pull-up function
 * 0 = Prohibit the corresponding port pull-up function
 */
void Gpio_P4_PurEn(Gpio_PinMaskType GpioPin, Gpio_PinPurType State)
{
    if (State == GPIO_PUR_EN)
    {
        PUR4 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        PUR4 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P4 Port Level Fluctuation Interrupt Enable
 * 1. The level change interrupt function can be enabled only when a pin is set as a digital input, and the level change
 * interrupt function will be disabled automatically when a pin is set as an output or analog input. If a pin is set as
 * output or analog input, the level change interrupt function of the pin will be disabled automatically.
 * 2. The level change interrupt of each pin of P0 port shares one interrupt enable bit and one interrupt response flag
 * bit.
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 1 = Enable the level fluctuation interrupt of the corresponding pin
 * 0 = Disable the level fluctuation interrupt of the corresponding pin
 */
void Gpio_P4_IocEn(Gpio_PinMaskType GpioPin, Gpio_PinIocType State)
{
    if (State == GPIO_IOC_EN)
    {
        IOCL4 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        IOCL4 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P5 Port Direction Control
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = The corresponding pin is configured as output
 * 1 = The corresponding pin is configured as input
 */
void Gpio_P5_DirCfg(Gpio_PinMaskType GpioPin, Gpio_PinDirType State)
{
    if (State == GPIO_INPUT)
    {
        TR5 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        TR5 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P5 Digital Port Configuration
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = Configure the corresponding pin as a digital port or special function pin
 * 1 = Configure the corresponding pin as an analog port
 */
void Gpio_P5_AnsCfg(Gpio_PinMaskType GpioPin, Gpio_PinAnsType State)
{
    if (State == GPIO_ANALOG)
    {
        ANS5 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        ANS5 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P5 Port Output Latch Settings
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 0 = Configure the corresponding pin as low level
 * 1 = Configure the corresponding pin as high level
 */
void Gpio_P5_OutLat(Gpio_PinMaskType GpioPin, Gpio_PinLevType State)
{
    if (State == GPIO_HIGH_LEVEL)
    {
        P5LR |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        P5LR &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief P5 Pull-up Function Enable
 * The pull-up resistor function can only be enabled when the pin is set as a digital input.
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @param State Pin status
 * 1 = Enable the corresponding port pull-up function
 * 0 = Prohibit the corresponding port pull-up function
 */
void Gpio_P5_PurEn(Gpio_PinMaskType GpioPin, Gpio_PinPurType State)
{
    if (State == GPIO_PUR_EN)
    {
        PUR5 |= (uint8_t)GpioPin;
    }
    else
    {
        /* PRQA S 4130, 4397 1 # This warning is not valid for 8-bit MCUs. */
        PUR5 &= ~((uint8_t)GpioPin);
    }
}

/**
 * @brief Get gpio status
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @return Gpio_Status Io port level status
 */
Gpio_Status Gpio_Get_P0_Status(Gpio_PinMaskType GpioPin)
{
    return (Gpio_Status)(P0 & (uint8_t)GpioPin);
}

/**
 * @brief Get gpio status
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @return Gpio_Status Io port level status
 */
Gpio_Status Gpio_Get_P1_Status(Gpio_PinMaskType GpioPin)
{
    return (Gpio_Status)(P1 & (uint8_t)GpioPin);
}

/**
 * @brief Get gpio status
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @return Gpio_Status Io port level status
 */
Gpio_Status Gpio_Get_P2_Status(Gpio_PinMaskType GpioPin)
{
    return (Gpio_Status)(P2 & (uint8_t)GpioPin);
}

/**
 * @brief Get gpio status
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @return Gpio_Status Io port level status
 */
Gpio_Status Gpio_Get_P3_Status(Gpio_PinMaskType GpioPin)
{
    return (Gpio_Status)(P3 & (uint8_t)GpioPin);
}

/**
 * @brief Get gpio status
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @return Gpio_Status Io port level status
 */
Gpio_Status Gpio_Get_P4_Status(Gpio_PinMaskType GpioPin)
{
    return (Gpio_Status)(P4 & (uint8_t)GpioPin);
}

/**
 * @brief Get gpio status
 *
 * @param GpioPin Pin mask, supports multi-pin inputs, like this: GPIO_PIN_MASK_1 | GPIO_PIN_MASK_5 or GPIO_PIN_MASK_ALL
 * @return Gpio_Status Io port level status
 */
Gpio_Status Gpio_Get_P5_Status(Gpio_PinMaskType GpioPin)
{
    return (Gpio_Status)(P5 & (uint8_t)GpioPin);
}

/**
 * @brief Vref input pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Vref_Select(Gpio_VrefType GpioPin)
{
    VREFINSEL1 = 0u;
    VREFINSEL0 = 0u;
    APFCTL0 |= (uint8_t)GpioPin;
}

/**
 * @brief P18 Outpin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_P18oe_Select(Gpio_P18oeType GpioPin)
{
    P18OE1 = 0u;
    P18OE0 = 0u;
    APFCTL0 |= (uint8_t)GpioPin;
}

/**
 * @brief Clk Outpin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_ClkOut_Select(Gpio_ClkOutType GpioPin)
{
    CLKOUTSEL1 = 0u;
    CLKOUTSEL0 = 0u;
    APFCTL0 |= (uint8_t)GpioPin;
}

/**
 * @brief Ccp3 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Ccp3_Select(Gpio_Ccp3Type GpioPin)
{
    CCP3SEL2 = 0u;
    CCP3SEL1 = 0u;
    CCP3SEL0 = 0u;
    APFCTL1 |= (uint8_t)GpioPin;
}

/**
 * @brief Ccp4 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Ccp4_Select(Gpio_Ccp4Type GpioPin)
{
    CCP4SEL2 = 0u;
    CCP4SEL1 = 0u;
    CCP4SEL0 = 0u;
    APFCTL1 |= (uint8_t)GpioPin;
}

/**
 * @brief P5D function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_P5d_Select(Gpio_P5dType GpioPin)
{
    P5DSEL1 = 0u;
    P5DSEL0 = 0u;
    APFCTL2 |= (uint8_t)GpioPin;
}

/**
 * @brief P5C function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_P5c_Select(Gpio_P5cType GpioPin)
{
    P5CSEL1 = 0u;
    P5CSEL0 = 0u;
    APFCTL2 |= (uint8_t)GpioPin;
}

/**
 * @brief P5B function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_P5b_Select(Gpio_P5bType GpioPin)
{
    P5BSEL1 = 0u;
    P5BSEL0 = 0u;
    APFCTL2 |= (uint8_t)GpioPin;
}

/**
 * @brief P5A function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_P5a_Select(Gpio_P5aType GpioPin)
{
    P5ASEL1 = 0u;
    P5ASEL0 = 0u;
    APFCTL2 |= (uint8_t)GpioPin;
}

/**
 * @brief PWM33 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Pwm33_Select(Gpio_Pwm33Type GpioPin)
{
    PWM33SEL = (uint8_t)GpioPin;
}

/**
 * @brief PWM32 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Pwm32_Select(Gpio_Pwm32Type GpioPin)
{
    PWM32SEL = (uint8_t)GpioPin;
}

/**
 * @brief PWM31 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Pwm31_Select(Gpio_Pwm31Type GpioPin)
{
    PWM31SEL = (uint8_t)GpioPin;
}

/**
 * @brief PWM22 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Pwm22_Select(Gpio_Pwm22Type GpioPin)
{
    PWM22SEL = (uint8_t)GpioPin;
}

/**
 * @brief PWM21 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Pwm21_Select(Gpio_Pwm21Type GpioPin)
{
    PWM21SEL = (uint8_t)GpioPin;
}

/**
 * @brief PWM20 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Pwm20_Select(Gpio_Pwm20Type GpioPin)
{
    PWM20SEL1 = 0u;
    PWM20SEL0 = 0u;
    APFCTL3 |= (uint8_t)GpioPin;
}

/**
 * @brief U1TC function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_U1tc_Select(Gpio_U1tcType GpioPin)
{
    U1TCSEL2 = 0u;
    U1TCSEL1 = 0u;
    U1TCSEL0 = 0u;
    APFCTL4 |= (uint8_t)GpioPin;
}

/**
 * @brief U1RD function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_U1rd_Select(Gpio_U1rdType GpioPin)
{
    U1RDSEL1 = 0u;
    U1RDSEL0 = 0u;
    APFCTL4 |= (uint8_t)GpioPin;
}

/**
 * @brief U2TC function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_U2tc_Select(Gpio_U2tcType GpioPin)
{
    U2TCSEL1 = 0u;
    U2TCSEL0 = 0u;
    APFCTL5 |= (uint8_t)GpioPin;
}

/**
 * @brief U2RD function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_U2rd_Select(Gpio_U2rdType GpioPin)
{
    U2RDSEL1 = 0u;
    U2RDSEL0 = 0u;
    APFCTL5 |= (uint8_t)GpioPin;
}

/**
 * @brief SDO function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Sdo_Select(Gpio_SdoType GpioPin)
{
    SDOSEL2 = 0u;
    SDOSEL1 = 0u;
    SDOSEL0 = 0u;
    APFCTL6 |= (uint8_t)GpioPin;
}

/**
 * @brief SCK function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Sck_Scl_Select(Gpio_SckSclType GpioPin)
{
    SCKSEL2 = 0u;
    SCKSEL1 = 0u;
    SCKSEL0 = 0u;
    APFCTL6 |= (uint8_t)GpioPin;
}

/**
 * @brief SS function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Ss_Select(Gpio_SsType GpioPin)
{
    SSSEL = (uint8_t)GpioPin;
}

/**
 * @brief SDI/SDA function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Sdi_Sda_Select(Gpio_SdiSdaType GpioPin)
{
    SDISEL3 = 0u;
    SDISEL2 = 0u;
    SDISEL1 = 0u;
    SDISEL0 = 0u;
    APFCTL7 |= (uint8_t)GpioPin;
}

/**
 * @brief BUZ3 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Buz3_Select(Gpio_Buz3Type GpioPin)
{
    BUZ3SEL = (uint8_t)GpioPin;
}

/**
 * @brief T1CK function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_T1ck_Select(Gpio_T1ckType GpioPin)
{
    T1CKSEL2 = 0u;
    T1CKSEL1 = 0u;
    T1CKSEL0 = 0u;
    APFCTL8 |= (uint8_t)GpioPin;
}

/**
 * @brief T1G function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_T1G_Select(Gpio_T1gType GpioPin)
{
    T1GSEL1 = 0u;
    T1GSEL0 = 0u;
    APFCTL8 |= (uint8_t)GpioPin;
}

/**
 * @brief T0CK function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_T0ck_Select(Gpio_T0ckType GpioPin)
{
    T0CKSEL1 = 0u;
    T0CKSEL0 = 0u;
    APFCTL8 |= (uint8_t)GpioPin;
}

/**
 * @brief INT1 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Int1_Select(Gpio_Int1Type GpioPin)
{
    INT1SEL2 = 0u;
    INT1SEL1 = 0u;
    INT1SEL0 = 0u;
    APFCTL9 |= (uint8_t)GpioPin;
}

/**
 * @brief INT2 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Int2_Select(Gpio_Int2Type GpioPin)
{
    INT2SEL1 = 0u;
    INT2SEL0 = 0u;
    APFCTL9 |= (uint8_t)GpioPin;
}

/**
 * @brief INT0 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Int0_Select(Gpio_Int0Type GpioPin)
{
    INT0SEL1 = 0u;
    INT0SEL0 = 0u;
    APFCTL9 |= (uint8_t)GpioPin;
}

/**
 * @brief CCP5 function pin selection bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Ccp5_Select(Gpio_Ccp5Type GpioPin)
{
    CCP5SEL2 = 0u;
    CCP5SEL1 = 0u;
    CCP5SEL0 = 0u;
    APFCTLB |= (uint8_t)GpioPin;
}

/**
 * @brief Ports pull-up total enable bit
 *
 * @param GpioPin Pin select
 */
void Gpio_Puph_Enable(Gpio_PinPuphType State)
{
    PUPH = (uint8_t)State;
}

/**
 * @brief P0 Deinitialization
 *
 */
void Gpio_P0_DeInit(void)
{
    TR0   = 0xffu;
    PUR0  = 0xffu;
    IOCL0 = 0x00u;
    ANS0  = 0xffu;
}

/**
 * @brief P1 Deinitialization
 *
 */
void Gpio_P1_DeInit(void)
{
    TR1  = 0xffu;
    PUR1 = 0xffu;
    ANS1 = 0xffu;
}

/**
 * @brief P2 Deinitialization
 *
 */
void Gpio_P2_DeInit(void)
{
    TR2  = 0xffu;
    PUR2 = 0xffu;
    ANS2 = 0xffu;
}

/**
 * @brief P3 Deinitialization
 *
 */
void Gpio_P3_DeInit(void)
{
    TR3  = 0xffu;
    PUR3 = 0xffu;
    ANS3 = 0xffu;
}

/**
 * @brief P4 Deinitialization
 *
 */
void Gpio_P4_DeInit(void)
{
    TR4   = 0xffu;
    PUR4  = 0xffu;
    IOCL4 = 0x00u;
    ANS4  = 0xffu;
}

/**
 * @brief P5 Deinitialization
 *
 */
void Gpio_P5_DeInit(void)
{
    TR5  = 0xffu;
    PUR5 = 0xffu;
    ANS5 = 0xffu;
}
/* EOF */
